﻿using DG.Tweening;
using UnityEngine;

public class WorldNumberTween : MonoBehaviour, ITween
{
    private WorldNumber _worldNumber;

    private void Awake()
    {
        _worldNumber = GetComponent<WorldNumber>();

        // var color = _worldNumber.TextMesh.color;
        // color.a = 0f;
        // _worldNumber.TextMesh.color = color;
        //
        // transform.localScale = Vector3.one * 4.5f;
    }

    public void Play()
    {
        DOTween.Sequence()
            .Append(transform.DOScale(Vector3.one, 0.35f).From(Vector3.one * 2f))
            .Join(_worldNumber.TextMesh.DOFade(1f, 0.1f).From(0f))
            .Join(transform.DOMoveY(transform.position.y + _worldNumber.TextMesh.fontSize * 0.2f, 0.1f))
            .AppendInterval(0.4f)
            .Append(_worldNumber.TextMesh.DOFade(0f, 0.15f))
            .OnComplete(() => _worldNumber.Stop());

        // var scaleSequence = DOTween.Sequence()
        //     .Append(transform.DOScale(Vector3.one * 1.25f, 0.25f).From(0f))
        //     .Append(transform.DOScale(Vector3.one, 0.25f));
        // DOTween.Sequence()
        //     .Append(_worldNumber.TextMesh.DOFade(1f, 0.25f).From(0f))
        //     .Join(scaleSequence)
        //     .Join(transform.DOMoveY(transform.position.y + 1.5f, 0.25f))
        //     .AppendInterval(0.5f)
        //     .Append(_worldNumber.TextMesh.DOFade(0f, 0.25f))
        //     .OnComplete(() => _worldNumber.Stop());
    }

    public void Stop()
    {
        var color = _worldNumber.TextMesh.color;
        color.a = 0f;
        _worldNumber.TextMesh.color = color;
    }
}